﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MessageAdd.aspx.cs" Inherits="CY.GFiveWeb.MessageManagement.WebForm1" %>
<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>
        <%= base.Settings.HotelName %>
        - 后台管理 - 添加站内信息</title>
    <link href="../style/screen.css" type="text/css" rel="stylesheet" charset="utf-8" />
</head>
<body class="dbody">
    <form id="mainForm" runat="server">
    <div id="sitemap">
        站内消息管理 &gt;&gt; <a href="MessageList.aspx">站内消息列表</a> &gt;&gt; 添加站内消息
    </div>
    <div id="ui">
        <p>
            <span>标题：</span><asp:TextBox ID="MessageTitle" CssClass="text" runat="server"></asp:TextBox>
        </p>
        <p>
            <span>内容：</span>
        </p>
        <div style="position: relative; left: 75px; top: -25px; width: 660px;">
            <FCKeditorV2:FCKeditor Width="600" Height="400" ID="MessageContent" runat="server"
                ToolbarSet="Simple">
            </FCKeditorV2:FCKeditor>
        </div>
        <p>
            <span>属性:</span>
            <asp:DropDownList ID="ddl_IsPub" runat="server">
                <asp:ListItem Text="公告消息" Selected="True" Value="1"></asp:ListItem>
                <asp:ListItem Text="非公告消息" Value="0"></asp:ListItem>
            </asp:DropDownList>
        </p>
        <div id="userobject" style="display: none; position: relative; left: 75px;">
            <span style="position: relative; left: -70px;">发送对象:</span>
            <input type="button" id="btAddUser" runat="server" class="button" value="添加用户" onclick="OpenEditWin('UsersList.aspx',500,400)"
                style="position: relative; left: -60px;" />
            <p id="userlist" runat="server" style="margin-top: 5px;">
            </p>
            <input id="tblistEmpty" style="display: none" value="1" runat="server" type="text" />
            <input id="tblistUsers" style="display: none" value="" runat="server" type="text" />
        </div>
        <p>
            <span></span>
            <asp:TextBox ID="tb_UserIDs" Style="display: none" runat="server" />
            <asp:Button ID="BtnSubmit" runat="server" Text="添加" CssClass="button" OnClick="BtnSubmit_Click" />
        </p>
    </div>
    <div style="height: 30px;">
    </div>
    </form>

    <script type="text/javascript" src="../script/jquery/jquery-1.2.6.min.js"></script>

    <script type="text/javascript" src="../script/jquery/jquery.json-1.3.min.js"></script>

    <script type="text/javascript" src="/script/cy/cy.js" charset="utf-8"></script>

    <script type="text/javascript" src="/script/cy/hb/cy.hb.message.js" charset="utf-8"></script>

    <script type="text/javascript">
        $(function() {
            $("#ddl_IsPub").change(function() {
                if ($("select option:selected").val() == 0) {
                    $("#userobject").show();
                }
                else {
                    $("#userobject").hide();
                }
            })
        });
        function OpenEditWin(frmWin, width, height) {
            var me;
            me = window;
            var ret = window.showModalDialog(frmWin, me, 'dialogWidth=' + width + 'px;dialogHeight=' + height + 'px;help:no;status:no');

            if (ret != null) {
                var strTable = "";
                var listEmpty = $("#tblistEmpty").val();
                if (listEmpty == "1") {
                    var HTML = "<table id='users' class='infoTable' border='1' style='width: 185px; border-collapse: collapse;'>";
                    HTML += "<thead>";
                    HTML += "<tr>";
                    HTML += "<th class='none'>";
                    HTML += "Id";
                    HTML += "</th>";

                    HTML += "<th>";
                    HTML += "用户名";
                    HTML += "</th>";

                    HTML += "<th>";
                    HTML += "用户姓名";
                    HTML += "</th>";
                    HTML += "<th>";
                    HTML += "&nbsp;";
                    HTML += "</th>";
                    HTML += "</tr>";
                    HTML += "</thead>";
                    strTable += HTML;
                    $("#tblistEmpty").val(0);
                }

                var HTML2 = "";
                var value = $("#tb_UserIDs").val();
                var listID = value.split(',');
                for (var j = 0; j < ret.Items.length; ++j) {
                    var item = ret.Items[j];
                    if (value != "") {
                        var HasID = false;
                        for (var i = 0; i < listID.length; ++i) {
                            if (listID[i] == item.ID) {
                                HasID = true;
                            }
                        }
                        if (!HasID) {
                            HTML2 += "<tr>";
                            HTML2 += "<td class='none'>";
                            value = value + "," + item.ID;
                            $("#tb_UserIDs").val(value);
                            HTML2 += item.ID;
                            HTML2 += "</td>";
                            HTML2 += "<td>";
                            HTML2 += item.Code;
                            HTML2 += "</td>";
                            HTML2 += "<td>";
                            HTML2 += item.Name;
                            HTML2 += "</td>";
                            HTML2 += "<td>";
                            HTML2 += "<a>删除</a>";
                            HTML2 += "</td>";
                            HTML2 += "</tr>";
                            strTable += HTML2;
                            HTML2 = "";
                        }
                    } else {
                        HTML2 += "<tr>";
                        HTML2 += "<td class='none'>";
                        value = item.ID;
                        HTML2 += item.ID;
                        HTML2 += "</td>";
                        HTML2 += "<td>";
                        HTML2 += item.Code;
                        HTML2 += "</td>";
                        HTML2 += "<td>";
                        HTML2 += item.Name;
                        HTML2 += "</td>";
                        HTML2 += "<td>";
                        HTML2 += "<a>删除</a>";
                        HTML2 += "</td>";
                        HTML2 += "</tr>";
                        strTable += HTML2;
                        HTML2 = "";
                    }
                }
                $("#tb_UserIDs").val(value);

                if (listEmpty == "1") {
                    var HTML3 = "</table>";
                    strTable += HTML3;
                    $("#userlist").append(strTable);
                }
                else {
                    $("#userlist").children().children("tbody").append(strTable);
                }
                $("#tblistUsers").val($("#userlist").html());

                $("#userlist  a").css("cursor", "pointer");

                $("#userlist  a").click(function() {
                    var strsID = $(this).parent().parent().children().html();
                    var listID = $("#tb_UserIDs").val().split(',');
                    var value = "";
                    for (var i = 0; i < listID.length; ++i) {
                        if (listID[i] != strsID) {
                            if (value == "") {
                                value = listID[i];
                            }
                            else {
                                value += "," + listID[i];
                            }
                        }
                    }
                    $("#tb_UserIDs").val(value);
                    $(this).parent().parent().remove();
                    if ($("#tb_UserIDs").val() == "") {
                        $("#userlist").html("");
                        $("#tblistEmpty").val(1);
                    }
                    $("#tblistUsers").val($("#userlist").html());
                });
            }
            var frame = window.parent.document.getElementById("contentFrame");

            if (frame && !window.opera) {
                if (frame.contentDocument && frame.contentDocument.body.offsetHeight) {
                    frame.height = frame.contentDocument.body.offsetHeight + 20;
                } else if (frame.Document && frame.Document.body.scrollHeight) {
                    frame.height = frame.Document.body.scrollHeight + 20;
                }
            }
        }
        cy.hotelbooking.message.add('mainForm');
    </script>

</body>
</html>
